package pswvclass.pswvandroid2.com;

import android.app.DownloadManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import pswvclass.pswvandroid2.R;
import pswvclass.pswvandroid2.com.kwords.KwordAdd;
import pswvclass.pswvandroid2.com.util.HttpUtils;

/**
 * Created by Administrator on 2018/11/14.
 */
public class Home extends Fragment implements View.OnClickListener {

    private Button payment_test;
    private Button xiazai;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return inflater.inflate(R.layout.home, null);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
      /*  payment_test = (Button) getView().findViewById(R.id.payment_test);
        payment_test.setOnClickListener(this);*/
      /* xiazai = (Button) getView().findViewById(R.id.xiazai);
        xiazai.setOnClickListener(this);*/
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
           /* case R.id.xiazai:
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://gdown.baidu.com/data/wisegame/55dc62995fe9ba82/jinritoutiao_448.apk"));
                //设置在什么网络情况下进行下载
                request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
                //设置通知栏标题
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
                request.setTitle("下载");
                request.setDescription("今日头条正在下载");
                request.setAllowedOverRoaming(false);
                //设置文件存放目录
                request.setDestinationInExternalFilesDir(getContext(), Environment.DIRECTORY_DOWNLOADS, "mydown");
                Log.v("","sdsdsd");
                break;
            case R.id.payment_test:
                Intent intent = new Intent(getActivity(), Payment.class);
                startActivity(intent);
                break;*/
            default:
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        getView().setFocusableInTouchMode(true);
        getView().requestFocus();
        getView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && i == KeyEvent.KEYCODE_BACK) {
                    Button kword_page = (Button) getActivity().findViewById(R.id.kword_page);
                    Button risk_page = (Button) getActivity().findViewById(R.id.risk_page);
                    Button need_page = (Button) getActivity().findViewById(R.id.need_page);
                    kword_page.setVisibility(getView().VISIBLE);
                    risk_page.setVisibility(getView().VISIBLE);
                    need_page.setVisibility(getView().VISIBLE);
                    kword_page.setBackground(getView().getContext().getResources().getDrawable(R.drawable.ditu1));
                    risk_page.setBackground(getView().getContext().getResources().getDrawable(R.drawable.ditu1));
                    need_page.setBackground(getView().getContext().getResources().getDrawable(R.drawable.ditu1));
                    getFragmentManager()
                            .beginTransaction()
                            .addToBackStack(null)
                            .replace(R.id.realtabcontent, new Home()).commit();
                    return true;
                }
                return false;
            }
        });
    }
}
